
export class UploadItem {
  fileName: string;
  fileSize: number;
  file: File;
  status: UploadStatus;
  progress: number;
  detail: string;
  reupload?:boolean=false
  /**
   *
   */
  constructor(fileName:string,fileSize:number,file:File,status:UploadStatus,progress=0,detail='') {
    this.fileName=fileName
    this.fileSize=fileSize
    this.file=file
    this.status=status
    this.progress=progress
    this.detail=detail    
  }



  formattedSize(){
    const units=['B','KB','MB','GB','TB']
    let uid=0
    let size=this.fileSize
    while (size>=1024) {
        size/=1024
        uid+=1
    }
  //  return [size.toFixed(0),units[uid]]
  return size.toFixed(0)+units[uid]
  }

  formattedStatus(){
    return UploadStatus[this.status]
  }

  formattedProgress(){
    return (this.progress*100).toFixed(2)+'%'
  }
  formattedName(max_length=15){
    if (this.fileName.length>max_length) {
      return this.fileName.slice(0,max_length-3)+'...'
    }else{
      return this.fileName
    }
  }

}

export enum UploadStatus {
  Waiting,
  Uploading,
  Error,
  Completed,
  Rejected,
  Existed,
  Stop,
}


